package com.heima.wemedia.controller.v1;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.pojo.WmUser;
import com.heima.wemedia.service.WmUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author by jojo
 * @Date 2022/2/27
 * @Description
 */
@RestController
@RequestMapping("/api/v1/user")
@Api(value = "自媒体用户API",tags = "自媒体用户API")
public class WmUserController {
    @Autowired
    private WmUserService wmUserService;

    @GetMapping("/findByName/{name}")
    @ApiOperation("根据名称查询自媒体用户信息")
    public ResponseResult findByName(@PathVariable("name") String name){
        LambdaQueryWrapper<WmUser> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(WmUser::getName,name);
        WmUser user = wmUserService.getOne(wrapper);
        return ResponseResult.okResult(user);
    }

    @PostMapping("save")
    @ApiOperation("保存自媒体用户信息")
    public ResponseResult save(@RequestBody WmUser wmUser){
        wmUserService.save(wmUser);
        return ResponseResult.okResult(wmUser);
    }

}
